package com.tangyuan.answer.controller;

import com.tangyuan.answer.service.AnswerService;
import com.tangyuan.answer.service.IWrongGradeService;
import com.tangyuan.common.result.Result;
import com.tangyuan.dto.AnswerCollentDto;
import com.tangyuan.dto.RemoveBojectDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@RequestMapping("/answer")
public class AnswerController {
    @Autowired
    AnswerService answerService;
    @Autowired
    private IWrongGradeService  wrongGradeService;

    //添加错题发来图片转换成oss的url
    @PostMapping("/addAnswerPicture")
    public Result addAnswerPicture(@RequestHeader(name = "Authorization",required = false) String token,@RequestParam("file") MultipartFile file){
        return answerService.addAnswerPicture(token,file);
    }

    // 添加调用百度的接口擦除图片 2024/5/31 上午 9:23 By 少帅
    @GetMapping("/erasePicture")
    public Result erasePicture(@RequestHeader(name = "Authorization",required = false) String token,@RequestParam("eraseUrl") String eraseUrl) throws IOException {
        return answerService.erasePicture(token, eraseUrl);
    }
    //用户添加错题
    @PostMapping("/addAnswer")
    public Result addAnswer(@RequestHeader(name = "Authorization",required = false) String token,@RequestBody AnswerCollentDto answerCollentDto){
          return answerService.addAnswer(token,answerCollentDto);
    }
    //编辑修改错题
    @GetMapping("/updateAnswer")
    public Result updateAnswer(@RequestHeader(name = "Authorization",required = false) String token,@RequestParam Long id,
                                                                            @RequestParam Long answerObjectId,
                                                                            @RequestParam(name = "gradeId",required = false) Long gradeId,
                                                                            @RequestParam String url ){
        return answerService.updateAnswer(token,id,answerObjectId,gradeId,url);
    }

    //用户根据错题id查询所有错题
    @GetMapping("/getAnswer")
    public Result getAnswer(@RequestHeader(name = "Authorization",required = false) String token,@RequestParam Long id,
                            @RequestParam(name = "gradeId", required =false) Long gradeId,
                            @RequestParam Integer pageNum,
                            @RequestParam Integer pageSize){
        return answerService.getAnswer(token,id,gradeId,pageNum,pageSize);
    }

    //用户根据错题id查询所有错题
    @GetMapping("/getAnswerGradeByAnswerObjectId")
    public Result getAnswer(@RequestHeader(name = "userId",required = false) Long userId,
                            @RequestParam Long answerObjectId){
        return wrongGradeService.getAnswerGradeByAnswerObjectId(userId,answerObjectId);
    }

    //用户根据错题id查询所有错题试卷
    @GetMapping("/getPaperGradeByAnswerObjectId")
    public Result getPaperGradeByAnswerObjectId(@RequestHeader(name = "userId",required = false) Long userId,
                            @RequestParam Long answerObjectId){
        return wrongGradeService.getPaperGradeByAnswerObjectId(userId,answerObjectId);
    }

    //创建新科目
    @GetMapping("/addObject")
    public Result addObject(@RequestHeader(name = "Authorization",required = false) String token,
                            @RequestParam String name){
        return answerService.addObject(token,name);
    }
    //进入主页 查询固定科目信息
    @GetMapping("/getFirstObject")
    public Result getFirstObject(@RequestHeader(name = "Authorization",required = false) String token){
        return answerService.getFirstObject(token);
    }

    //查看我创建学科
    @GetMapping("/getObject")
    public Result getObject(@RequestHeader(name = "Authorization",required = false) String token){
        return answerService.getObject(token);
    }
    //根据用户id获取所有学科信息
    @GetMapping("/getAllObject")
    public Result getAllObject(@RequestHeader(name = "Authorization",required = false) String token){
        return answerService.getAllObject(token);
    }


    //删除我创建的学科
    @PostMapping("/removeObject")
    public Result removeObject(@RequestHeader(name = "Authorization",required = false) String token, @RequestBody RemoveBojectDto removeBojectDto){
        return answerService.removeObject(token,removeBojectDto);
    }
    //修改错题名字
    @GetMapping("/serAnswerName")
    public Result serAnswerName(@RequestHeader(name = "Authorization",required = false) String token,@RequestParam String name,@RequestParam Long id){
        return answerService.serAnswerName(token,name,id);
    }
    //删除错题
    @GetMapping("/removeAnswerName")
    public Result removeAnswerName(@RequestHeader(name = "Authorization",required = false) String token, @RequestParam Long id){
        return answerService.removeAnswerName(token,id);
    }
    //错题合卷
    @PostMapping("/answerToPaper/save")
    public Result answerToPaper(@RequestHeader(name = "Authorization",required = false) String token,
                                @RequestParam(value = "file",required = false) MultipartFile file,
                                @RequestParam(value = "gradeId",required = false) Long gradeId,
                                @RequestParam Long objectId,
                                @RequestParam(value = "paperUrl",required = false) String paperUrl){
        return answerService.answerToPaper(token,file,objectId,gradeId,paperUrl);
    }

    @GetMapping("/getpaperById")
    public Result getPaperById(@RequestHeader(name = "Authorization",required = false) String token,
                               @RequestParam(name = "gradeId",required = false) Long gradeId,
                               @RequestParam Long objectId,
                               @RequestParam Integer pageNum,
                               @RequestParam Integer pageSize){
        return answerService.getPaperById(token,objectId,gradeId,pageNum,pageSize);
    }
    @GetMapping("/removepaperById")
    public Result removePaperById(@RequestHeader(name = "Authorization",required = false) String token,@RequestParam Long id){
        return answerService.removePaperById(token,id);
    }

    @GetMapping("/getWrongGradeList")
    public Result getWrongGradeList(@RequestHeader(name = "userId",required = false) Long userId){
        return wrongGradeService.getWrongGradeList(userId);
    }


    //创建新科目年纪
    @GetMapping("/addAnswerObjectGrade")
    public Result addAnswerObjectGrade(@RequestHeader(name = "userId",required = false) Long userId,
                            @RequestParam String gradeName,
                            @RequestParam Long answerObjectId){
        return answerService.addAnswerObjectGrade(userId,gradeName,answerObjectId);
    }









}
